<template>
	<view class="pd16_15">
		
		<view class="box pd20_15">
			<view class="flex alcenter">
				<view class="ft14 cl-main" style="width: 144rpx;">
					收货姓名
				</view>
				<view style="width: calc(100% - 144rpx);">
					<input :maxlength="64" v-model="form.name" placeholder="输入收货人姓名"  class="ft14 cl-main inputh" placeholder-class="cl-notice" />
				</view>
			</view>
			<view class="bd-line"></view>
			<view class="flex alcenter">
				<view class="ft14 cl-main" style="width: 144rpx;">
					收货电话
				</view>
				<view style="width: calc(100% - 144rpx);">
					<input :maxlength="11" v-model="form.tel" type="number" placeholder="输入收货人手机号"  class="ft14 cl-main inputh" placeholder-class="cl-notice" />
				</view>
			</view>
			<view class="bd-line"></view>
			<view class="flex alcenter">
				<view class="ft14 cl-main" style="width: 144rpx;">
					收货地址
				</view>
				<view style="width: calc(100% - 144rpx);">
					<!-- <biaofun-region  @change="onChangeRegion"></biaofun-region> -->
					<biaofun-region :defaultValue="defaultValue" @change="onChangeRegion"></biaofun-region>
				</view>
			</view>
			
			<view class="bd-line"></view>
			<view class="flex alcenter">
				<view class="ft14 cl-main" style="width: 144rpx;">
					详细地址
				</view>
				<view style="width: calc(100% - 144rpx);">
					<input :maxlength="255" v-model="form.address" placeholder="输入收货人详细地址"  class="ft14 cl-main inputh" placeholder-class="cl-notice" />
				</view>
			</view>
			<view class="bd-line"></view>
			<view class="flex alcenter mt15" @click="changeDefault">
				<text class="iconfont ft20" :class="form.is_default == 0 ? 'iconicon_selector_disable' : 'iconicon_selector_enable'" :style="{color:form.is_default == 1 ? tempColor:'#E4E6ED'}"></text>
				<text class="ft14 ml10 cl-main">设为默认</text>
			</view>
			
		</view>
		
		<view class="mt24">
			<button class="btn-big" @click="postdata()" :style="getBtnStyle">确定修改</button>
		</view>
	</view>
</template>

<script>
import biaofunRegion from '@/components/biaofun-region/biaofun-region.vue';
export default {
		components: {
			biaofunRegion
		},
		data(){
			return {
				address_id:0,
				form:{
					id:'',
					name:'',
					tel:'',
					is_default:0,
					province:'',//省
					city:'',//市
					district:'',//区
					address:'',//详细地址
				},
				defaultValue: [], // 默认值
				address:'',
			}
		},
		onLoad(e){
			this.form=uni.getStorageSync("AdditemData")
			this.defaultValue=[this.form.province,this.form.city,this.form.city]
			uni.setNavigationBarTitle({
			    title: '编辑地址'
			});
		},
		onShow() {
			
		},
		methods:{
			
			opdt(){
				uni.chooseLocation({
				    success: function (res) {
				        console.log('位置名称：' + res.name);
				        console.log('详细地址：' + res.address);
				        console.log('纬度：' + res.latitude);
				        console.log('经度：' + res.longitude);
				    }
				});
			},
			changeDefault(){
				this.form.is_default = this.form.is_default == 0 ? 1 : 0;
			},
			onChangeRegion(region) {
				this.form.province=region[0].name
				this.form.city=region[1].name
				this.form.district=region[2].name
				
				console.log(this.form);
			},
			async postdata(){
				console.log(this.form);
				let _this=this;
				let data = this.form;
				if(!data.name){
					uni.showToast({ title: '请填写名字',icon:"none" });
					return
				}
				if(!data.tel){
					uni.showToast({ title: '请填写电话',icon:"none" });
					return
				}
				if(!data.province){
					uni.showToast({ title: '请选择省',icon:"none" });
					return
				}
				if(!data.city){
					uni.showToast({ title: '请选择市',icon:"none" });
					return
				}
				if(!data.district){
					uni.showToast({ title: '请选择区/县',icon:"none" });
					return
				}
				if(!data.address){
					uni.showToast({ title: '请填写详细地址',icon:"none" });
					return
				}
				data.token = uni.getStorageSync("userinfo").token;
				data.uid = uni.getStorageSync("userinfo").id;
				let [err,res] =await this.$httpas.post('/api/user/addadd',data);
				if (!this.$httpas.errorCheck(err,res)) return;
			
				if(res.data.code === 1){
					uni.showModal({
						title: '',
						content: res.data.msg,
						showCancel: false,
						confirmText: "确定",
						success: function (res) {
							if (res.confirm) {
								uni.navigateBack();
							} else if (res.cancel) {
								
							}
						}
					});
				}else{
					uni.showToast({ title: res.data.msg,icon:"none" });
				}
			},

		}
	}
</script>

<style>
	.row {
		display: flex;
		height: 100upx;
		align-items: center;
		color: #040506;
		border-bottom: 1upx solid rgba($color: #707070, $alpha: 0.3);
	}
	
	.row:active {
		opacity: 0.8;
	}
	.inputh{
		height: 100upx;
	}
	.name {
		flex-shrink: 0;
	}
	
	.value {
		flex: 1;
	}
	
	.right-icon {
		color: #707070;
	}
</style>